import type { CSSProperties } from 'vue'

type ValidationTrigger = 'input' | 'change' | 'blur' | 'focus'

type RuleType =
  | 'string'
  | 'number'
  | 'boolean'
  | 'method'
  | 'regexp'
  | 'integer'
  | 'float'
  | 'array'
  | 'object'
  | 'enum'
  | 'date'
  | 'url'
  | 'hex'
  | 'email'
  | 'pattern'
  | 'any'

export interface ElementJson {
  type: string // naive-ui组件名称小驼峰，不带n-
  key: string // 表单提交字短名称
  label: string // 表单label
  props?: any // 组件props
  style?: CSSProperties // 组件style
  // 表单校验规则
  rule?: {
    type?: RuleType
    required?: boolean
    pattern?: RegExp | string
    message?: string
    trigger?: ValidationTrigger | string | Array<ValidationTrigger | string>
  }
}

export interface PageJSON {
  title: string
  elements: ElementJson[]
}

export interface ModelJson {
  pages?: PageJSON[]
  elements?: ElementJson[]
}
